import os
import struct
import asyncio
import logging

logger = logging.getLogger('filesolver')
logging.basicConfig(level=logging.DEBUG)


async def read_file(file, offset, size):
    """
        It's a bit wasteful here, but I found that there will be problem when using seek in CRLF file
    """
    with open(file, 'rb') as f:
        f.seek(offset)
        content = f.read(size).decode()
        return content


async def get_metadata(file):
    if os.path.exists(file):
        logger.debug('File {} found.'.format(file))
        filesize = os.path.getsize(file)
        return filesize
    else:
        logger.warning('File {} not found!'.format(file))
        return False


if __name__ == '__main__':
    a = list(range(0, 111, 20))
    print(a)

# a = 'this is a test'
# a.encode()
# # print(a.encode())
# # print(type(a.encode()))
#
# a = 'this'
# b = 'is'
#
# stri = struct.pack("ss", a, b)  # 转换后的str虽然是字符串类型，但相当于其他语言中的字节流（字节数组），可以在网络上传输
# print(stri)
# print(repr(stri))

# print(WHITE)
# message = json.dumps({'file':'README.md', 'offset':0, 'size':20})
# a = json.loads(message)
# b = '10085'
# b.encode()
# print(type(b))
# print(a['file'])
#
# class tesd:
#     def __init__(self):
#         pass
#
#     def theli(self):
#         return [1, 2, 3]
